package com.baomidou.springwind.test;

/**
 * Created by Administrator on 2016/12/8.
 */

interface Cycle {
    boolean move();
}

interface CycleFactory {
    Cycle getCycle();
}


class Unicycle implements Cycle {
    private static final int MOVIE = 1;
    private int movie = 0;
    public static CycleFactory cycleFactory = new CycleFactory() {
        @Override
        public Cycle getCycle() {
            return new Unicycle();
        }
    };
    @Override
    public boolean move() {
//        System.out.println(movie);
        return ++movie != MOVIE;
    }
}

class Bicycle implements Cycle {
    private static final int MOVIE = 2;
    private int movie = 0;
    public static CycleFactory cycleFactory = new CycleFactory() {
        @Override
        public Cycle getCycle() {
            return new Bicycle();
        }
    };
    @Override
    public boolean move() {
//        System.out.println(movie);
        return ++movie != MOVIE;
    }
}
class Tricycle implements Cycle {
    private static final int MOVIE = 3;
    private int movie = 0;
    public static CycleFactory cycleFactory = new CycleFactory() {
        @Override
        public Cycle getCycle() {
            return new Tricycle();
        }
    };
    @Override
    public boolean move() {
//        System.out.println(movie);
        return ++movie != MOVIE;
    }
}

class UnicycleFactory implements CycleFactory {
    @Override
    public Cycle getCycle() {
        return new Unicycle();
    }
}
class BicycleFactory implements CycleFactory {
    @Override
    public Cycle getCycle() {
        return new Bicycle();
    }
}

class TricycleFactory implements CycleFactory {
    @Override
    public Cycle getCycle() {
        return new Tricycle();
    }
}

public class Main {

    public static void getCycle(CycleFactory cycleFactory) {
        Cycle cycle = cycleFactory.getCycle();
        while (cycle.move()) {

        }
    }

    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();

/*            getCycle(new UnicycleFactory());
            getCycle(new BicycleFactory());
            getCycle(new TricycleFactory());*/


        getCycle(Unicycle.cycleFactory);
        getCycle(Bicycle.cycleFactory);
        getCycle(Tricycle.cycleFactory);

        long endTime = System.currentTimeMillis();
        System.out.println("花费时间");
        System.out.println((endTime - startTime));

    }
}
